home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 February (DVD) / PCWorld_2008-02_DVD.iso / v cisle / PHP / PHP.exe / EasyPHP-2.0b1-setup.exe / {app} / sqlitemanager / include / sqlite2.class.php < prev    next >
Encoding:
PHP Script  |  2006-04-18  |  4.7 KB  |  142 lines

  1. <?php
  2. include_once dirname(__FILE__) . '/sqlite.class.php';
  3.  
  4. class sqlite2 extends sqlite {
  5.  
  6.     function sqlite2($dbPath) {
  7.         $this->dbVersion = 2;
  8.         if($dbPath == ':memory:') {
  9.             $this->readOnly = false;            
  10.         } else {
  11.             $this->readOnly = !is_writable($dbPath);
  12.         } 
  13.         parent::sqlite($dbPath);
  14.         $this->connect($dbPath);
  15.     }
  16.     
  17.     function connect($dbPath) {
  18.         if(DEBUG) {
  19.             if($dbPath == ':memory:') $this->connId = sqlite_popen($dbPath, 0666, $this->error);
  20.             else $this->connId = sqlite_open($dbPath, 0666, $this->error);
  21.         } else {
  22.             if($dbPath == ':memory:') $this->connId = @sqlite_popen($dbPath, 0666, $this->error);
  23.             else $this->connId = @sqlite_popen($dbPath, 0666, $this->error);
  24.         }
  25.         return $this->connId;
  26.     }
  27.     
  28.     function getError($errorCode = null) {
  29.         if(!$this->error) $this->error = sqlite_last_error($this->connId);
  30.         if($errorCode == null) $errorCode = $this->error;
  31.         $this->errorMessage = sqlite_error_string($errorCode);
  32.         return $this->errorMessage;
  33.     }
  34.     
  35.     function getErrorMessage() {
  36.         return $this->errorMessage;
  37.     }
  38.     
  39.     function query($sqlString, $buffered = true, $assign = true) {
  40.          if(substr(trim($sqlString), -1) != ';') $sqlString .= ';';
  41.         if($buffered) {
  42.             if(DEBUG) {
  43.                 $resId = sqlite_query($this->connId, $sqlString);
  44.             } else {
  45.                 $resId = @sqlite_query($this->connId, $sqlString);
  46.             }
  47.         } else {
  48.             if(DEBUG) $resId = sqlite_unbuffered_query($this->connId, $sqlString);
  49.             else $resId = @sqlite_unbuffered_query($this->connId, $sqlString);
  50.         }
  51.         if($assign) $this->resId = $resId;
  52.         return $resId;
  53.     }
  54.     
  55.     function array_query($sqlString, $result_type=SQLITE_BOTH, $decode_binary=true) {
  56.         if(DEBUG) return sqlite_array_query($this->connId, $sqlString, $result_type, $decode_binary);
  57.         else return @sqlite_array_query($this->connId, $sqlString, $result_type, $decode_binary);
  58.     }
  59.     
  60.     function num_rows($resId = null) {
  61.         if($resId == null) $resId = $this->resId;
  62.         if(DEBUG) $out =  sqlite_num_rows($resId);
  63.         else $out =  @sqlite_num_rows($resId);
  64.         return $out;
  65.     }
  66.     
  67.     function fetch_single($resId=null, $result_type=SQLITE_BOTH) {
  68.         if($resId == null) $resId = $this->resId;
  69.         if(DEBUG) $out =  sqlite_fetch_string($resId,$result_type);
  70.         else $out =  @sqlite_fetch_string($resId,$result_type);
  71.         return $out;
  72.     }
  73.     
  74.     function fetch_array($resId=null, $result_type=SQLITE_BOTH,$decode_binary=true) {
  75.         if($resId == null) $resId = $this->resId;
  76.         if(DEBUG) $out =  sqlite_fetch_array($resId,$result_type, $decode_binary);
  77.         else $out =  @sqlite_fetch_array($resId,$result_type, $decode_binary);
  78.         return $out;
  79.     }
  80.  
  81.     function last_insert_id() {
  82.         return sqlite_last_insert_rowid($this->connId);
  83.     }    
  84.     
  85.     function changes() {
  86.         if(DEBUG) $out =  sqlite_changes($this->connId);
  87.         else $out =  @sqlite_changes($this->connId);
  88.         return $out;        
  89.     }
  90.         
  91.     function num_fields($resId = null) {
  92.         if($resId == null) $resId = $this->resId;
  93.         if(DEBUG) $out =  sqlite_num_fields($resId);
  94.         else $out =  @sqlite_num_fields($resId);
  95.         return $out;        
  96.     }
  97.  
  98.     function field_name($resId = null, $index) {
  99.         if($resId == null) $resId = $this->resId;
  100.         if(DEBUG) $out =  sqlite_field_name($resId, $index);
  101.         else $out =  @sqlite_field_name($resId, $index);
  102.         return $out;        
  103.     }
  104.  
  105.     function create_function($function_name, $callback, $num_arg=null) {
  106.         if(DEBUG) return sqlite_create_function($this->connId, $function_name, $callback, $num_arg);
  107.         else return @sqlite_create_function($this->connId, $function_name, $callback, $num_arg);
  108.     }
  109.     
  110.     function create_aggregate($function_name, $step_func, $finalize_func, $num_args=null) {
  111.         if(DEBUG) return sqlite_create_aggregate($this->connId, $function_name, $step_func, $finalize_func, $num_args);
  112.         else return @sqlite_create_aggregate($this->connId, $function_name, $step_func, $finalize_func, $num_args);
  113.     }
  114.         
  115.     function sqlite_version() {
  116.         return sqlite_libversion();
  117.     }
  118.     
  119.     function close() {
  120.         if(DEBUG) return sqlite_close($this->connId);
  121.         else return @sqlite_close($this->connId);
  122.     }
  123.     
  124.     function sqlitem_busy_timeout($milliseconds=0) {
  125.         if(DEBUG) $out = sqlite_busy_timeout($this->connId, $milliseconds);
  126.         else $out = @sqlite_busy_timeout($this->connId, $milliseconds);
  127.         return $out;
  128.     }
  129.  
  130.     function beginTransaction() {
  131.         $this->query('BEGIN TRANSACTION;', false, false);
  132.     }
  133.     
  134.     function commitTransaction() {
  135.         $this->query('COMMIT TRANSACTION;', false, false);
  136.     }
  137.     
  138.     function rollBackTransaction() {
  139.         $this->query('ROLLBACK TRANSACTION;', false, false);
  140.     }
  141. }
  142. ?>